'''
    1.实现充值模块相关接口的测试用例
'''
import unittest
import requests

import utils
from api.api_recharge import RechargeApi
from api.api_reg_login import RegLoginApi


class TestRecharge(unittest.TestCase):

    def setUp(self) -> None:
        # 创建session对象
        self.session = requests.session()
        # 调用封装的充值模块类
        self.recharge_api = RechargeApi(self.session)
        # 实例化登录模块封装的类
        self.reg_login_api = RegLoginApi(self.session)
        # 调用登录接口，完成用户登录
        self.reg_login_api.user_login("18800011121", "123qqq")

    def tearDown(self) -> None:
        # 关闭session对象
        self.session.close()

    # 获取充值验证码测试用例
    def test01_get_recharge_verify_code(self):
        # 获取充值图片验证码
        res = self.recharge_api.get_recharge_verify_code(0.12321333333)
        # 断言
        self.assertEqual(200, res.status_code)

    # 充值测试用例
    def test02_recharge(self):
        # 获取充值图片验证码
        self.recharge_api.get_recharge_verify_code(0.12321333333)
        # 充值
        res = self.recharge_api.recharge("50000", "8888")
        # 断言
        utils.common_assert(self, res, 200, 200, "form")

    # 第三方充值测试用例
    def test03_third_recharge(self):
        # 获取充值图片验证码
        self.recharge_api.get_recharge_verify_code(0.12321333333)
        # 充值
        res = self.recharge_api.recharge("50000", "8888")
        # 获取第三方开户接口的url
        url = utils.html_util(res)[0]
        # 获取第三方开户接口的请求体数据
        data_form = utils.html_util(res)[1]
        # 获取第三方接口返回的响应结果
        res_3 = self.recharge_api.third_recharge(url, data_form)
        # 断言
        self.assertIn("OK", res_3.text)
